package com.hyp.pay.UI.Home.activity;

import android.app.Activity;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;

import com.hyp.pay.R;
import com.hyp.pay.base.SimpleActivity;
import com.hyp.pay.camera.CameraHelper;
import com.hyp.pay.camera.CameraHelper2;
import com.hyp.pay.camera.MaskSurfaceView;
import com.hyp.pay.camera.MaskSurfaceView2;
import com.hyp.pay.camera.OnCaptureCallback;
import com.hyp.pay.utils.DensityUtil;

import butterknife.BindView;
import butterknife.ButterKnife;

public class RectCameraActivity extends SimpleActivity implements OnCaptureCallback {

    @BindView(R.id.surface_view)
    MaskSurfaceView mSurfaceView;
    @BindView(R.id.btn_capture)
    ImageView mBtnCapture;
    //	拍照后得到的保存的文件路径
    private String mFilePath;

    @Override
    protected int getLayout() {
        return R.layout.activity_rect_camera;
    }

    @Override
    protected void initEventAndData() {
//		设置矩形区域大小
        this.mSurfaceView.setMaskSize(DensityUtil.dip2px(300), DensityUtil.dip2px(400));


//		拍照
        mBtnCapture.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                CameraHelper.getInstance().tackPicture(RectCameraActivity.this);
            }
        });


    }


    @Override
    public void onCapture(boolean success, String filePath) {
        this.mFilePath = filePath;
        String message = "拍照成功";
        if (!success) {
            message = "拍照失败";
            CameraHelper.getInstance().startPreview();
            this.mSurfaceView.setVisibility(View.VISIBLE);
        } else {
            CameraHelper.getInstance().startPreview();
            Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
            setResult(Activity.RESULT_OK, new Intent().putExtra("filePath", mFilePath));
            finish();
        }

    }
}
